package com.ljm.controller;

import com.ljm.daomain.CommonResult;
import com.ljm.service.AccountService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.concurrent.TimeUnit;

/**
 * @author PengHuAnZhi
 * @createTime 2021/2/25 17:55
 * @projectName SpringCloudDemo
 * @className AccountController.java
 * @description TODO
 */
@RestController

public class AccountController {

    @Resource
    private AccountService accountService;

    @RequestMapping("/account/decrease")
    public CommonResult decrease(@RequestParam("userId") Long userId, @RequestParam("money") BigDecimal money){
        //模拟超时异常，暂停20秒
//        try {
//            TimeUnit.SECONDS.sleep(20);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
       // int a=10/0;
        accountService.decrease(userId, money);
        return new CommonResult(200, "扣减库存成功!");
    }

}

